<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class veh_trouble_list_frame extends Page
{
       public $btnSearch = null;
       public $edtSearch = null;
       public $Image4 = null;
       public $JTJavaScript2 = null;
       public $JTJavaScript1 = null;
       public $Image1 = null;
       public $imgAdd = null;
       public $hfVehId = null;
       public $JTSiteTheme1 = null;
       public $JTTroubleList = null;

       function btnSearchClick($sender, $params)
       {
       redirect('veh_trouble_list_frame.php?veh_id='.$this->hfVehId->getValue());


       }

       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function imgAddJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new.png"
       <?php

       }

       function imgAddJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php

       }
       function imgAddJSClick($sender, $params)
       {

       ?>
       var veh_id = document.getElementById('hfVehId').value;
       var win_height = 240;
       var win_width = 536;
       var height = window.outerHeight;
       var width = window.outerWidth;
       var top = Math.round((height-win_height)/2);
       var left = Math.round((width-win_width)/2);
       window.open("veh_trouble_create.php?veh_id="+veh_id, 'Create Trouble', 'location=no,height='+win_height+',width='+win_width+',top='+top+',left='+left);
       <?php

       }

       function veh_trouble_list_frameCreate($sender, $params)
       {
       $veh_id = $_GET['veh_id'];
       if($veh_id!='' && $veh_id!=null)
       $this->hfVehId->setValue($veh_id);

       }

       function JTTroubleListShow($sender, $params)
       {
       $veh_id = $this->hfVehId->getValue();

       //$grid_arr = array();

       //$query_trouble = "SELECT distinct(start_date) as start_date FROM veh_trouble_tbl WHERE veh_id='".$veh_id."' ORDER BY start_date DESC";
       //$result_trouble = mysql_query($query_trouble) or die("TROUBLE ".mysql_error());
       //while($row_trouble = mysql_fetch_array($result_trouble))
      //{
       /* $query_details = "SELECT * FROM veh_trouble_tbl WHERE veh_id = '".$this->hfVehId->getValue()."' and start_date='".$row_trouble['start_date']."' and
       (start_date like '%".$this->edtSearch->Text."%'
       or end_date like '%".$this->edtSearch->Text."%'
       or remedy like '%".$this->edtSearch->Text."%'
       or serviced_by like '%".$this->edtSearch->Text."%')";
        $result_details = mysql_query($query_details) or die("TROUBLE DETAILS ".mysql_error()); */

        $query_details = "SELECT * FROM veh_trouble_tbl WHERE veh_id = '".$this->hfVehId->getValue()."' and
       (start_date like '%".$this->edtSearch->Text."%'
       or end_date like '%".$this->edtSearch->Text."%'
       or remedy like '%".$this->edtSearch->Text."%'
       or serviced_by like '%".$this->edtSearch->Text."%'
       or trouble_name like '%".$this->edtSearch->Text."%') order by flag_used ASC,start_date DESC";
        $result_details = mysql_query($query_details) or die("TROUBLE DETAILS ".mysql_error());


        /*$br_end_date = "";
        $end_date = "";
        $br_trouble = "";
        $br_remedy = "";
        $br_serviced_by = "";
        $tools = "";*/
        $grid_arr = array();
        while($row_details = mysql_fetch_array($result_details))
        {
         $lookup_trouble_id = $row_details['trouble'];
         $lookup_remedy_id = $row_details['remedy'];

        $trou_color = $row_details['flag_used'];

        if($trou_color==1)
        {
        $color = "Gray";
        }

        if($trou_color==0)
        {
        $color = "Black";
        }

         $query_trouble = "SELECT * FROM trouble_droplist_tbl WHERE autoid = '".$lookup_trouble_id."' and value like '%".$this->edtSearch->Text."%'";
         $result_trouble = mysql_query($query_trouble) or die("LOOKUP DETAILS ".mysql_error());
         $row_trouble = mysql_fetch_array($result_trouble);

         $query_remedy = "SELECT * FROM remedy_droplist_tbl WHERE autoid = '".$lookup_remedy_id."' and value like '%".$this->edtSearch->Text."%'";
         $result_remedy = mysql_query($query_remedy) or die("LOOKUP DETAILS ".mysql_error());
         $row_remedy = mysql_fetch_array($result_remedy);


         /*$br_end_date .= $row_details['end_date']."<br/>";
         $br_trouble .= $row_lookup['value']."<br/>";
         if($row_details['remedy']!='-1')
         {
         $br_remedy .= $row_details['remedy']."<br/>";
         }
         if($row_details['remedy']=='-1')
         {
         $br_remedy .= "<br/>";
         }
         $br_serviced_by .= $row_details['serviced_by']."<br/>"; */

         $autoid = $row_details['autoid'];

         $start_date= "<span onclick=js_edit('".$autoid."'); title='edit' style='cursor:pointer;color:".$color.";text-decoration:underline'>".$row_details['start_date']."</span>"."<br/>";
         $tools= "<img onclick=js_delete('".$autoid."'); src='image/delete.png' title='delete' style='cursor:pointer'><br/>";

        //die($end_date);
        $grid_arr[] = array(
        "Start Date"=>"<p style='color:".$color."'>".$start_date."</p>",
        "End Date"=>"<p style='color:".$color."'>".$row_details['end_date']."</p>",
        "Trouble"=>"<p style='color:".$color."'>".$row_trouble['value']."</p>",
        "Remedy"=>"<p style='color:".$color."'>".$row_details['remedy']."</p>",
        "Serviced By"=>"<p style='color:".$color."'>".$row_details['serviced_by']."</p>",
        "Tools"=>$tools
        );

        }

       //}
       $this->JTTroubleList->setCellData($grid_arr);
       }

}

global $application;

global $veh_trouble_list_frame;

//Creates the form
$veh_trouble_list_frame=new veh_trouble_list_frame($application);

//Read from resource file
$veh_trouble_list_frame->loadResource(__FILE__);

//Shows the form
$veh_trouble_list_frame->show();

?>